package com.lanca.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;

@RestController
public class DemoController {

    private static final Logger log = LoggerFactory.getLogger(DemoController.class);

    @Value("${customer.username}")
    private String username;

    @GetMapping("/demo")
    public String demo() {
        //
        return "demo username: " + username;
    }

    public static void main(String[] args) throws IOException {
        File oldPic = new File("e:\\Zxr\\zxr.jpg");
        File newPic = new File("e:\\Zxr\\zxr2.jpg");
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(oldPic);
            fos = new FileOutputStream(newPic);
            byte[] buf = new byte[1024];
            int readLine = 0;
            // fis.read(buf)一次读取buf（10224）字节
            while ((readLine = fis.read(buf)) != -1) {
                // 写入读取的字节数，因为在读取文件最后的时候，不一定是读到1024个字节的，因此 fos.write(buf, 0, readLine);
                fos.write(buf, 0, readLine);
            }
            System.out.println("copy 成功");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

    public void test() {
//        File file = new File("E:\\javaFile\\springcloud_alibaba_parent" + "\\springcloud_alibaba_04configclient\\src\\main\\resources\\aaaaa.txt");
//        if (!file.isFile()) {
//            //boolean mkdir = file.mkdir();
//            file.mkdirs();
//            file.createNewFile();
//        }
//        try (FileInputStream fis = new FileInputStream(file);) {
//            byte[] b = new byte[1024];
//            int len;
//            while ((len = fis.read(b)) != -1) {
//                System.out.println(new String(b, 0, len));
//            }
//            //System.out.println(fileInputStream.read());
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }
}
